//
// Created by daiyizheng on 2022/3/27.
//
#include <iostream>
using namespace std;
struct TreeNode {
    int val;
    TreeNode *left;
    TreeNode *right;
    TreeNode() : val(0), left(nullptr), right(nullptr) {}
    TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}
    TreeNode(int x, TreeNode *left, TreeNode *right) : val(x), left(left), right(right) {}
};
TreeNode * postOrder(TreeNode *node){
    if (node== nullptr)return nullptr;
    if(node->left== nullptr && node->right== nullptr)return node;

    TreeNode *left = postOrder(node->left);
    TreeNode *right = postOrder(node->right);
    node->left = right;
    node->right = left;
    return node;


}
TreeNode* invertTree(TreeNode* root) {
    return postOrder(root);
}